package zip;

import net.lingala.zip4j.core.ZipFile;
import net.lingala.zip4j.exception.ZipException;

/**
 * Created by jinju on 2016/5/5.
 */
public class Unzip {
    public static void main(String[] args) throws Exception{
        long startTime = System.currentTimeMillis();

        UnZipPassword unZipPassword = new UnZipPassword(10);
        ZipFile zipFile = null;
        String password = null;
        zipFile = new ZipFile("f:\\UnzipTest.zip"); // 根据路径取得需要解压的Zip文件
        while (true) {
            try {
                password = unZipPassword.getPassword();
                zipFile.setPassword(password);
                System.out.print(password);

//                if (zipFile.isEncrypted()) { // 判断文件是否加码
//                    zipFile.setPassword("123456"); // 密码为123456
//                }


                zipFile.extractAll("f:\\"); // 压缩包文件解压路径

            } catch (ZipException e) {
//                e.printStackTrace();
                System.out.println("    失败！");
                unZipPassword.next();
                continue;
            }
            System.out.println("    成功！");
            break;
        }

        long endTime = System.currentTimeMillis();
        System.out.println("耗时(毫秒):" + (endTime - startTime));


    }
}
